package com.zjitc.controller;

import com.sun.org.apache.bcel.internal.generic.MONITORENTER;
import com.zjitc.model.Category;
import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import java.lang.ProcessBuilder.Redirect;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/25 15:53
 * @description:
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;
  /*  @RequestMapping("/findByCid")
    public ModelAndView findByCid(HttpSession session){
      ModelAndView modelAndView=new ModelAndView();
      List<Category> list=productService.findAllCategory();
      session.setAttribute("list",list);
      modelAndView.setViewName("/user/productList.jsp");
      return modelAndView;
    }*/

   @RequestMapping("/findByPid")
    private ModelAndView findByPid(@RequestParam(name = "pid") Integer pid){
      ModelAndView modelAndView=new ModelAndView();
      Product product=productService.findByPid(pid);
      modelAndView.addObject("pl",product);
      modelAndView.setViewName("/user/productList.jsp");
      return modelAndView;
    }

    @RequestMapping("/findAllProduct")
    private ModelAndView findAllProduct(){
      ModelAndView modelAndView=new ModelAndView();
      List<Product> products=productService.findAllProduct();
      modelAndView.addObject("pal",products);
      modelAndView.setViewName("/user/productList.jsp");
      return modelAndView;
    }

}
